package win.bitterwine.action;

import org.smart4j.framework.ioc.annotation.Inject;
import org.smart4j.framework.mvc.DataContext;
import org.smart4j.framework.mvc.annotation.Action;
import org.smart4j.framework.mvc.annotation.Request;
import org.smart4j.framework.mvc.bean.Params;
import org.smart4j.framework.mvc.bean.Result;
import org.smart4j.framework.mvc.bean.View;
import win.bitterwine.BasicService.BasicService;
import win.bitterwine.entity.B_roles;
import win.bitterwine.service.B_rolesService;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/6/15.
 */
@Action
public class B_rolesAction {

    @Inject
    private B_rolesService b_rolesService;
    @Inject
    private BasicService basicService;

    @Request.Get("/users")
    public View index() {
        List<B_roles> userList = b_rolesService.findRolesList();
        DataContext.Request.put("userList", userList);
        return new View("user.jsp");
    }

    @Request.Get("/user")
    public View create() {
        return new View("user_create.jsp");
    }

    @Request.Post("/user")
    public Result save(Params params) {
        Map<String, Object> fieldMap = params.getFieldMap();
        long result = basicService.save(B_roles.class, fieldMap);
        System.out.println("comeon:"+result);
        return new Result(true);
    }


    @Request.Get("/getID/{id}")
    public Result nss(long id) {
        //B_roles roles = (B_roles) basicService.findById(B_roles.class, id);
        //List<B_roles> b_roles = basicService.selectListWithSort(B_roles.class, "id desc");
        B_roles b_roles = basicService.selectOneObj(B_roles.class, "id=?", 3);
        //List<B_roles> b_roles = basicService.selectListWithConditionAndSort(B_roles.class,"id > ?", "id desc", 5);
        //List<B_roles> b_roles = basicService.selectList(B_roles.class);
        long count = basicService.selectCount(B_roles.class);
        //List<B_roles> b_roles = basicService.selectListForPager(2, 5, B_roles.class, "", "id desc");
        //Map<Long, B_roles> longB_rolesMap = basicService.selectMap(B_roles.class);
        Result result = new Result(true);
        result.setData(b_roles);
        return result;
    }

//    @Request.Get("/user/{id}")
//    public View edit(long id) {
//        B_roles user = b_rolesService.findRoles(id);
//        DataContext.Request.put("user", user);
//        return new View("user_edit.jsp");
//    }

//    @Request.Put("/user/{id}")
//    public Result update(long id, Params params) {
//        Map<String, Object> fieldMap = params.getFieldMap();
//        boolean result = b_rolesService.updateRoles(id, fieldMap);
//        return new Result(result);
//    }

    @Request.Get("/user/{id}")
    public Result delete(long id) {
        System.out.println("delete...");
        boolean result = basicService.delete(B_roles.class,20);
        return new Result(result);
    }
}
